const rl = require("readline").createInterface({ input: process.stdin })

const cache = {}
const list = []
rl.on('line', (line) => {
  if (line === 'end') {
    rl.close()
    return
  }

  const [path, num] = line.split(' ')
  const fileName = getFileName(path)
  const key = `${fileName}${num}`

  if (cache[key]) {
    cache[key].count ++
  } else {
    cache[key] = {
      fileName,
      num,
      count: 1
    }
    list.push(cache[key])
  }
})

rl.on('close', () => {
  const len = list.length
  let subList
  if (len <= 8) {
    subList = list
  } else {
    subList = list.slice(len - 8)
  }
  for (const item of subList) {
    console.log(`${item.fileName} ${item.num} ${item.count}`)
  }
})

function getFileName (path, bit = 16) {
  if (!path) return
  const items = path.split('\\')
  const name = items[items.length - 1]
  return name.length <= bit ? name : name.substring(name.length - bit)
}
